package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/shop")
@RestController
@Api(tags = "店铺")
@Slf4j
public class ShopController {
    @Autowired
    RedisTemplate redisTemplate;


    /**
     * @return 设置营业状态
     * @Description:
     * @author 小陈
     * @Params:
     * @DateTime:
     */
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status) {
        //1.接受请求参数:path , @PathVariable
        log.info("设置店铺状态：{}", status);
        //2.更新redis中存储的店铺营业状态
        redisTemplate.opsForValue().set(MessageConstant.SHOP_STATUS, status);
        //3.封装/返回处理结果
        return Result.success(status);
    }

    /**
     * @return 获取营业状态
     * @Description:
     * @author 小陈
     * @Params:
     * @DateTime:
     */
    @GetMapping("/{status}")
    public Result getShopStatus() {
        //1.接受请求参数:path , @PathVariable
        log.info("获取店铺状态");
        //2.更新redis中存储的店铺营业状态
        Integer status = (Integer) redisTemplate.opsForValue().get(MessageConstant.SHOP_STATUS);
        //3.封装/返回处理结果
        return Result.success(status);
    }


}
